// 集中管理请求地址、请求头与请求体构建

// 环境配置（按需切换）
const ENV = {
  API_BASE: 'https://652js.suse.edu.cn/',
  MAPI_BASE: 'https://test.uu163yun.com/mapi/', 
  WS_URL: 'wss://realtime-test.uu163yun.com/',
  videoBaseUrl:'https://652js.suse.edu.cn/video/',
  imgBaseUrl: 'https://652js.suse.edu.cn/images/',
  iconBaseUrl:'https://652js.suse.edu.cn/icon/',
  mp3BaseUrl:'https://652js.suse.edu.cn/mp3/',
  backendUrl: 'https://652js.suse.edu.cn/',
};

// 统一导出 WebSocket 地址
const WS_URL = ENV.WS_URL;

// 各业务端点（若需要参数，用函数返回完整地址）
const endpoints = {
  CHAT_ASK: `${ENV.MAPI_BASE}/Helper/Chat/Ask`,
  CHAT_STOP: `${ENV.MAPI_BASE}/Helper/Chat/Stop`,
  HISTORY_SESSIONS: (userId) => `${ENV.API_BASE}api/chat/history/sessions?userId=${encodeURIComponent(userId || '')}`,
  HISTORY_SESSION: (userId, sessionId) => `${ENV.API_BASE}api/chat/history/session?userId=${encodeURIComponent(userId || '')}&sessionId=${encodeURIComponent(sessionId || '')}`,
  HISTORY_SAVE: `${ENV.API_BASE}api/chat/history/save`,
  HISTORY_USER: (userId) => `${ENV.API_BASE}api/chat/history/user/${encodeURIComponent(userId || '')}`,
  STORY_LIST: `${ENV.API_BASE}api/story/list`,
  STORY_ID:`${ENV.API_BASE}api/story/`,
  PHOTO_LIST: `${ENV.API_BASE}api/img/client/user`
};

// 网关默认请求头（可覆盖 ApiVersion 等）
function mapiHeaders(userToken = "", opts = {}) {
  const {
    ApiVersion = "6.0",
    ApiWay = "API",
    MerId = "dc529a26P-aecd-4727-86c4-cb62ad24ab99",
    VendorId = "350",
  } = opts;
  return {
    ApiVersion,
    ApiWay,
    MerId,
    VendorId,
    UserToken: userToken || "",
  };
}

// JSON 请求头（本地后端）
function jsonHeaders(userToken = "") {
  return {
    "content-type": "application/json",
    UserToken: userToken || "",
  };
}

// 统一的请求体构建
function buildChatAsk(content = "") {
  return {
    endpointCode: 'Suse652-1',
    endpointVersion: '1.0.0',
    type: 'BaiduAgent',
    returnFullReply: 'false',
    content
  };
}

function buildChatStop(userGuid = "") {
  return {
    endpointCode: 'Suse652-1',
    endpointVersion: '1.0.0',
    type: 'BaiduAgent',
    userGuid
  };
}

export default {
  WS_URL,
  endpoints,
  mapiHeaders,
  jsonHeaders,
  buildChatAsk,
  buildChatStop,
    ENV
};
